home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_04 / 2n04045a < prev    next >
Text File  |  1990-12-27  |  3KB  |  99 lines

  1. #include    "sm.h"
  2. #include    <stdio.h>
  3. #include    <string.h>
  4. #include    <conio.h>
  5. #include    <io.h>
  6. #include    <fcntl.h>
  7. #include    <sys\stat.h>
  8. #include    <stdlib.h>
  9.  
  10. /******************************************************************
  11. *    Output speech file stored using record().
  12. *
  13. *    Parameters:
  14. *        Filename to output.
  15. *
  16. *    Notes:
  17. *        1.    This routine will output any file, using any compression
  18. *            scheme supported by Covox.  It outputs the entire file.
  19. *
  20. *        2.    Compiled using TurboC's large memory model.
  21. *
  22. *        3.    Requires sm.h and cvxtlcc.lib, supplied by Covox.
  23. *
  24. *        4.    As written, the routine outputs to the Voice Master speaker.
  25. *
  26. *    Copyright:
  27. *        Original code by William H. Roetzheim (619) 669-6970
  28. *        Copyright 1990 by William H. Roetzheim
  29. *        All rights reserved.
  30. **********************************************************************/
  31.  
  32. void main (int argc, char *argv[])
  33. {
  34.     int        i;
  35.     long    lLength;
  36.     char    *lpBuffer;
  37.     char    szFileName[15];
  38.     int        nFile;
  39.  
  40.     if (argc != 2)
  41.     {
  42.         printf ("\nsyntax:  Say filename");
  43.         exit (-1);
  44.     }
  45.  
  46.     /* test for extension in filename */
  47.     for (i = 0; i < strlen (argv[1]); i++)
  48.     {
  49.         if (argv[1][i] == '.')
  50.         {
  51.             printf ("\n File name should not have an extension.");
  52.             exit (-1);
  53.         }
  54.     }
  55.  
  56.     strcpy (szFileName, argv[1]);
  57.     strcat (szFileName, ".v3s");
  58.     printf ("\nOpening %s.", szFileName);
  59.     nFile = open (szFileName, O_BINARY | O_RDONLY, S_IREAD | S_IWRITE);
  60.     if (nFile == -1)
  61.     {
  62.         printf ("\nError opening file.");
  63.         exit (-1);
  64.     }
  65.  
  66.     lLength = filelength(nFile);
  67.     if (lLength > 0xFFFF)
  68.     {
  69.         printf ("\nFile too large.");
  70.         exit (-1);
  71.     }
  72.  
  73.     lpBuffer = malloc ((size_t) lLength);
  74.     lseek (nFile, 0, SEEK_SET);
  75.     if (read (nFile, lpBuffer, (unsigned) lLength) != lLength)
  76.     {
  77.         printf ("\nError reading file.");
  78.         exit (-1);
  79.     }
  80.  
  81.     /* The four main parameters for this function are as follows */
  82.     /*         lpBuffer points to the start of the buffer to be output */
  83.     /*            for PCM files (not compressed), this can be a location */
  84.     /*            within the file.  For compressed data, it MUST be the start */
  85.     /*            of the buffer so the header can be found. */
  86.     /*        lLength is the number of samples to be output.  For all files */
  87.     /*            (including compressed files), this can be less than the full */
  88.     /*            sample size. */
  89.     /*      The fourth parameter (second zero here) is the port number */
  90.     /*            Of particular interest are 0 for Voice Master (factory default) */
  91.     /*            4 for LPT1: as used by the Speech Thing and the Sound Master, and */
  92.     /*            8 for the PC's internal speaker. */
  93.     if (say (lpBuffer, lLength, 0, 0, 0, 0) == 1)
  94.     {
  95.         printf ("\nError during playback.");
  96.     }
  97.     close (nFile);
  98.     free (lpBuffer);
  99. }